package util;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.util.ResourceBundle;

import javax.swing.JColorChooser;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import modelUtil.Util;
import paginas.PaginaAspectoBoton;
import AccionBoton.AccionCambioColorFondo;
import AccionBoton.AccionCerrar;
import AccionBoton.AccionCerrarCruz;
import AccionBoton.AccionFocoCreditos;

public class PopUpSeleccionColorFondo extends JDialog implements ChangeListener{

	private PaginaAspectoBoton _frame;
	private JColorChooser _selector;
	private Color newColor;
	
	public PopUpSeleccionColorFondo(PaginaAspectoBoton frame){
		
		_frame = frame;
		
		JPanel panel = new JPanel();
		GridBagLayout grid = new GridBagLayout();
		GridBagConstraints cons = new GridBagConstraints();
		FlowLayout flow = new FlowLayout();
		panel.setLayout(flow);
		cons.fill = GridBagConstraints.BOTH;
		cons.gridheight = 1;
		cons.gridwidth = 1;
		cons.gridx = 0;
		cons.gridy = 0;
		setLayout(grid);
		_selector = new JColorChooser(_frame.get_boton().getBackground());
		grid.addLayoutComponent(_selector, cons);
		this.add(_selector);
		cons.gridy = 1;
		grid.addLayoutComponent(panel, cons);
		this.add(panel);
		
		
		 _selector.getSelectionModel().addChangeListener(this);

			BotonPersonalizado aceptar = Util.BotonImagen(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_popup_admin_aceptar"), "lib//Aceptar.png");
			BotonPersonalizado cancelar = Util.BotonImagen(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_popup_admin_cancelar"), "lib//cancelar.png");
			
			aceptar.getLabelImagen().setHorizontalAlignment(SwingConstants.LEFT);
			aceptar.getLabelTexto().setHorizontalAlignment(SwingConstants.RIGHT);
			cancelar.getLabelImagen().setHorizontalAlignment(SwingConstants.LEFT);
			cancelar.getLabelTexto().setHorizontalAlignment(SwingConstants.RIGHT);
			aceptar.setBackground(Color.lightGray);
			cancelar.setBackground(Color.lightGray);
			aceptar.setMnemonic('a');
			cancelar.setMnemonic('c');
			aceptar.getLabelImagen().setDisplayedMnemonic('a');
			cancelar.getLabelImagen().setDisplayedMnemonic('c');


			aceptar.setPreferredSize(new Dimension(150,40));
			cancelar.setPreferredSize(new Dimension(150,40));

			aceptar.addFocusListener(new AccionFocoCreditos(aceptar));
			cancelar.addFocusListener(new AccionFocoCreditos(cancelar));
			
			aceptar.addActionListener(new AccionCambioColorFondo(this));
			cancelar.addActionListener(new AccionCerrar(this, _frame));
		 
			panel.setPreferredSize(new Dimension(320,50));
			flow.addLayoutComponent("aceptar", aceptar);
			panel.add(aceptar);
			flow.addLayoutComponent("cancelar", cancelar);
			panel.add(cancelar);

		addComponentListener(new AccionCerrarCruz(this,_frame));
		setBounds(0, 0, 600, 500);
		setAlwaysOnTop(true);
		setLocationRelativeTo(null);
		setModal(true);
		this.pack();
		this.repaint();
		setVisible(true);
		
	}
	

	public void stateChanged(ChangeEvent e){
		
        newColor = _selector.getColor();

	}


	public PaginaAspectoBoton get_frame() {
		return _frame;
	}


	public void set_frame(PaginaAspectoBoton frame) {
		_frame = frame;
	}


	public Color getNewColor() {
		return newColor;
	}


	public void setNewColor(Color newColor) {
		this.newColor = newColor;
	}
	
	
	
}
